//this is a note
#include "queue.h"


//定义
template<typename Element>
lqueue<Element>::lqueue()
{
    front = nullptr;
    rear = nullptr;
}

template<typename Element>
void lqueue<Element>::in(Element newData)
{
    node<Element>* s = new node<Element>;
    s->data = newData; //存储数据
    s->next = nullptr;
    if (rear == nullptr) {//若队列为空
        rear = s;		//使尾指针指向新节点
        front = s;
    }
    else {//队列不为空
        rear->next = s; //连接新节点
        rear = s;  //更新尾指针（rear指向的节点变换）
    }
}

template<typename Element>
inline bool lqueue<Element>::isEmpty()
{
    if (front == nullptr) return true;
    else return false;
}

template<typename Element>
Element lqueue<Element>::out()
{
    if (rear == nullptr) throw 队列为空;
            Element x = front->data;
    node<Element>* s = front;
    front = front->next;
    if (front == nullptr) rear = nullptr;
    delete s;  //删除队头节点（获取了数据，保证了删除前后的连接）
    return x;
}
